package tankgame;

import java.util.Vector;

/**
 * @author: lizhiwen
 * @version: 1.0
 */
public class CreateEnemyTank implements Runnable{
    Vector<EnemyTank> enemyTanks = new Vector<>();
    Vector<Wall> walls = new Vector<>();

    public CreateEnemyTank(Vector<EnemyTank> enemyTanks,Vector<Wall> walls) {
        this.enemyTanks = enemyTanks;
        this.walls = walls;
    }

    //每隔十秒自动新增坦克
    @Override
    public void run() {
        while (true) {
            //左边
            EnemyTank enemyTank = new EnemyTank(0, 100);
            enemyTank.setEnemyTanks(enemyTanks);
            enemyTank.setWalls(walls);
            enemyTank.setDirect(1);
            new Thread(enemyTank).start();
            Shot shot = new Shot(enemyTank.getX() + 20, enemyTank.getY() + 60, enemyTank.getDirect());
            enemyTank.shots.add(shot);
            new Thread(shot).start();
            enemyTanks.add(enemyTank);
            //右边
            EnemyTank enemyTank2 = new EnemyTank(940, 100);
            enemyTank2.setEnemyTanks(enemyTanks);
            enemyTank2.setWalls(walls);
            enemyTank2.setDirect(3);
            new Thread(enemyTank2).start();
            Shot shot2 = new Shot(enemyTank2.getX() + 20, enemyTank2.getY() + 60, enemyTank2.getDirect());
            enemyTank2.shots.add(shot);
            new Thread(shot).start();
            enemyTanks.add(enemyTank2);
            //上方
            EnemyTank enemyTank3 = new EnemyTank(500, 0);
            enemyTank3.setEnemyTanks(enemyTanks);
            enemyTank3.setWalls(walls);
            enemyTank3.setDirect(2);
            new Thread(enemyTank3).start();
            Shot shot3 = new Shot(enemyTank3.getX() + 20, enemyTank3.getY() + 60, enemyTank3.getDirect());
            enemyTank3.shots.add(shot);
            new Thread(shot).start();
            enemyTanks.add(enemyTank3);
            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
